package zf.liao.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import zf.liao.domain.User;
import zf.liao.service.IUserService;

@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    private IUserService userService;

    @GetMapping("/get")
    public User get(Long id){
        User user = userService.getById(id);
        return user;
    }
    @PostMapping("/save")
    public String save(User user){
        boolean save = userService.save(user);
        String str = save? "操作成功":"操作失败";
        return str;

    }
    @DeleteMapping("/delete/{id}")
    public String del(@PathVariable("id") Long id){
        boolean b = userService.removeById(id);
        String str = b? "操作成功":"操作失败";
        return str;
    }
    @PutMapping("/update")
    public String update(User user){
        boolean b = userService.updateById(user);
        String str = b? "操作成功":"操作失败";
        return str;
    }
}
